/**
 * @param {string} s
 * @return {number}
 */
var lengthOfLongestSubstring = function (s) {
    let pStart = 0
    let pEnd = 0
    let maxLength = 0
    let sArr = s.split('')

    while (pEnd !== sArr.length) {
        let subArr = sArr.slice(pStart, pEnd)
        const index = subArr.findIndex(item => item === sArr[pEnd])
        pStart = index === -1 ? pStart : index + pStart +1
        pEnd++
        maxLength = Math.max((pEnd - pStart), maxLength)
    }
    return maxLength
};